//
//  GameObject.h
//  Agility
//
//  Created by Dominique d'Argent on 15.03.11.
//  Copyright 2011 Nicky Nubbel. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "GameData.h"

@class GameObjectLayer;


//
// GameObject
//
// This is the base class for all game objects.
//
@interface GameObject : NSObject {
    NSString *gameObjectKey;
    NSUInteger changes;
    NSTimeInterval lifeTime;
    NSTimeInterval maxLifeTime;
    NSTimeInterval spawnTime;
    CGPoint position;
    CGPoint destination;
    CGFloat destinationAngle;       // in radian
    CGFloat trajectory;             // in radian
    CGFloat angle;                  // in radian
    CGFloat velocity;               // in pixels  per second
    CGFloat angularVelocity;        // in radians per second
    BOOL visible;
    NSTimeInterval durationForMovement;
    NSTimeInterval durationForRotation;
    NSString *imageName;
    GameObjectLayer *layer;
}

@property (nonatomic, copy) NSString *gameObjectKey;
@property (nonatomic) NSTimeInterval lifeTime;
@property (nonatomic) NSTimeInterval maxLifeTime;
@property (nonatomic) NSTimeInterval spawnTime;
@property (nonatomic) CGPoint position;
@property (nonatomic) CGPoint destination;
@property (nonatomic) CGFloat destinationAngle;
@property (nonatomic) CGFloat trajectory;
@property (nonatomic) CGFloat angle;
@property (nonatomic) CGFloat velocity;
@property (nonatomic) CGFloat angularVelocity;
@property (nonatomic) BOOL visible;
@property (nonatomic, readonly) NSTimeInterval durationForMovement;
@property (nonatomic, readonly) NSTimeInterval durationForRotation;
@property (nonatomic, copy) NSString *imageName;
@property (nonatomic, retain) GameObjectLayer *layer;
@property (nonatomic, readonly) CGSize size;
@property (nonatomic, readonly) CGPoint currentPosition;
@property (nonatomic, readonly) CGRect currentFrame;
@property (nonatomic, readonly) CGFloat currentAngle;
@property (nonatomic, readonly) CGFloat collisionRadius;

- (id)initWithImageNamed:(NSString *)newImageName;
- (BOOL)hasChanges;
- (void)resetChanges;
- (void)updateWithValue:(NSValue *)value;
- (BOOL)updateWithTimeInterval:(NSTimeInterval)timeInterval;
- (BOOL)updateLifeTimeWithTimeInterval:(NSTimeInterval)timeInterval;
- (void)updatePositionWithTimeInterval:(NSTimeInterval)timeInterval;
- (void)updateTransformWithTimeInterval:(NSTimeInterval)timeInterval;
- (BOOL)collidesWithGameObject:(GameObject *)testObject;
- (BOOL)didCollideWithGameObject:(GameObject *)collidingObject;
- (CGFloat)angleToPoint:(CGPoint)thePoint;
- (CGFloat)angularDistanceToAngle:(CGFloat)theAngle;
- (CGFloat)distanceToPoint:(CGPoint)thePoint;
- (NSTimeInterval)durationForMovementToPoint:(CGPoint)thePoint;
- (NSTimeInterval)durationForRotationToAngle:(CGFloat)theAngle;

@end

extern const NSTimeInterval kGameObjectDefaultDuration;
